package com.ykt.model;

import com.ykt.common.utils.UB;

import java.util.List;

/**
 * 系统地址
 * @author long.hua
 * @version 1.0.0
 * @since 2016-01-30 11:26
 */
public class Address extends BaseModel<Address>{
    private static final long serialVersionUID = 1L;

    public static final String parent_id ="parent_id";
    public static final String level = "level";

    public static Address dao = new Address();


    public int getId(){
        return UB.i(getInt(Address.id), -1);
    }

    public int getParentId(){
        return UB.i(getInt(Address.parent_id), -1);
    }

    public String getName(){
        return getStr(Address.name);
    }

    public int getLevel(){
        return UB.i(getInt(Address.level), -1);
    }

    public List<Address> findAll(){
        return this.find("select * from address where level < 4");
    }

    public List<Address> findByIds(List<Integer> ids){
        if(ids == null || ids.isEmpty()){
            return null;
        }

        StringBuilder sb=new StringBuilder();
        for (Integer id : ids) {
            sb.append(id).append(",");
        }
        sb.deleteCharAt(sb.length()-1);

        return this.find(String.format("select * from address where id in (%s)", sb.toString()));
    }

    public List<Address> findByParentId(int parentId){
        return this.find("select * from address where parent_id=?", parentId);
    }

}
